package com.feifan;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;

/**
 * 启动程序
 * 
 * @author ruoyi
 */
@MapperScan("com.feifan.oa.mapper")
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class FeiFanApplication
{
    public static void main(String[] args)
    {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(FeiFanApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  OA自动化办公系统启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .----------------.  .----------------.  .----------------.    .----------------.  .----------------" +
                ".  .-----------------.\n" +
                "| .--------------. || .--------------. || .--------------. |  | .--------------. || .--------------." +
                " || .--------------. |\n" +
                "| |  _________   | || |  _________   | || |     _____    | |  | |  _________   | || |      __      |" +
                " || | ____  _____  | |\n" +
                "| | |_   ___  |  | || | |_   ___  |  | || |    |_   _|   | |  | | |_   ___  |  | || |     /  \\     " +
                "| || ||_   \\|_   _| | |\n" +
                "| |   | |_  \\_|  | || |   | |_  \\_|  | || |      | |     | |  | |   | |_  \\_|  | || |    / /\\ \\" +
                "    | || |  |   \\ | |   | |\n" +
                "| |   |  _|      | || |   |  _|  _   | || |      | |     | |  | |   |  _|      | || |   / ____ \\   " +
                "| || |  | |\\ \\| |   | |\n" +
                "| |  _| |_       | || |  _| |___/ |  | || |     _| |_    | |  | |  _| |_       | || | _/ /    \\ \\_" +
                " | || | _| |_\\   |_  | |\n" +
                "| | |_____|      | || | |_________|  | || |    |_____|   | |  | | |_____|      | || ||____|  |____||" +
                " || ||_____|\\____| | |\n" +
                "| |              | || |              | || |              | |  | |              | || |              |" +
                " || |              | |\n" +
                "| '--------------' || '--------------' || '--------------' |  | '--------------' || '--------------'" +
                " || '--------------' |\n" +
                " '----------------'  '----------------'  '----------------'    '----------------'  " +
                "'----------------'  '----------------'");
    }

    /*HTTPS*/
    @Bean
    public Connector connector(){
        Connector connector=new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8090);
        connector.setSecure(false);
        connector.setRedirectPort(8091);
        return connector;
    }

    @Bean
    public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){
        TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory(){
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint=new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection=new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(connector);
        return tomcat;
    }
}